<template>
  <a-modal
    title="编辑车型表"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item v-show="false"><a-input v-decorator="['id']" /></a-form-item>
        <a-form-item
          label="系统id"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入系统id" v-decorator="['systemId', {rules: [{required: true, message: '请输入系统id！'}]}]" />
        </a-form-item>
        <a-form-item
          label="汽车之家车型id"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入汽车之家车型id" v-decorator="['qczjModelId', {rules: [{required: true, message: '请输入汽车之家车型id！'}]}]" />
        </a-form-item>
        <a-form-item
          label="品牌id"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入品牌id" v-decorator="['brandId', {rules: [{required: true, message: '请输入品牌id！'}]}]" />
        </a-form-item>
        <a-form-item
          label="品牌名称"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入品牌名称" v-decorator="['brandName', {rules: [{required: true, message: '请输入品牌名称！'}]}]" />
        </a-form-item>
        <a-form-item
          label="车系id"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入车系id" v-decorator="['seriesId', {rules: [{required: true, message: '请输入车系id！'}]}]" />
        </a-form-item>
        <a-form-item
          label="车系名称"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入车系名称" v-decorator="['seriesName', {rules: [{required: true, message: '请输入车系名称！'}]}]" />
        </a-form-item>
        <a-form-item
          label="车型名称"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入车型名称" v-decorator="['modelName', {rules: [{required: true, message: '请输入车型名称！'}]}]" />
        </a-form-item>
        <a-form-item
          label="由于车辆型号是从车行168（大搜车旗下）爬取，所以用此ID与其对应。"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入由于车辆型号是从车行168（大搜车旗下）爬取，所以用此ID与其对应。" v-decorator="['dscModelId', {rules: [{required: true, message: '请输入由于车辆型号是从车行168（大搜车旗下）爬取，所以用此ID与其对应。！'}]}]" />
        </a-form-item>
        <a-form-item
          label="车型配置信息"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入车型配置信息" v-decorator="['modelJson', {rules: [{required: true, message: '请输入车型配置信息！'}]}]" />
        </a-form-item>
        <a-form-item
          label="车型编码"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入车型编码" v-decorator="['modelCode', {rules: [{required: true, message: '请输入车型编码！'}]}]" />
        </a-form-item>
        <a-form-item
          label="外观颜色"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入外观颜色" v-decorator="['appearanceColor', {rules: [{required: true, message: '请输入外观颜色！'}]}]" />
        </a-form-item>
        <a-form-item
          label="内饰颜色"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入内饰颜色" v-decorator="['interiorColor', {rules: [{required: true, message: '请输入内饰颜色！'}]}]" />
        </a-form-item>
        <a-form-item
          label="销售类型"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入销售类型" v-decorator="['saleType', {rules: [{required: true, message: '请输入销售类型！'}]}]" />
        </a-form-item>
        <a-form-item
          label="年款"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入年款" v-decorator="['modelYear', {rules: [{required: true, message: '请输入年款！'}]}]" />
        </a-form-item>
        <a-form-item
          label="排量(车型首页)"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入排量(车型首页)" v-decorator="['exhaust', {rules: [{required: true, message: '请输入排量(车型首页)！'}]}]" />
        </a-form-item>
        <a-form-item
          label="变速箱（车型首页）"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入变速箱（车型首页）" v-decorator="['shiftBox', {rules: [{required: true, message: '请输入变速箱（车型首页）！'}]}]" />
        </a-form-item>
        <a-form-item
          label="上市日期"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入上市日期" v-decorator="['launchDate', {rules: [{required: true, message: '请输入上市日期！'}]}]" />
        </a-form-item>
        <a-form-item
          label="车身结构"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入车身结构" v-decorator="['bodyTypeName', {rules: [{required: true, message: '请输入车身结构！'}]}]" />
        </a-form-item>
        <a-form-item
          label="发动机类型"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入发动机类型" v-decorator="['engineTypeName', {rules: [{required: true, message: '请输入发动机类型！'}]}]" />
        </a-form-item>
        <a-form-item
          label="级别（车型首页）"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入级别（车型首页）" v-decorator="['carGrade', {rules: [{required: true, message: '请输入级别（车型首页）！'}]}]" />
        </a-form-item>
        <a-form-item
          label="汽车类型"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入汽车类型" v-decorator="['carType', {rules: [{required: true, message: '请输入汽车类型！'}]}]" />
        </a-form-item>
        <a-form-item
          label="子品牌id"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入子品牌id" v-decorator="['subBrandNo', {rules: [{required: true, message: '请输入子品牌id！'}]}]" />
        </a-form-item>
        <a-form-item
          label="子品牌名称"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入子品牌名称" v-decorator="['subBrandName', {rules: [{required: true, message: '请输入子品牌名称！'}]}]" />
        </a-form-item>
        <a-form-item
          label="指导价"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
        </a-form-item>
        <a-form-item
          label="环保标准（车型首页）"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入环保标准（车型首页）" v-decorator="['emissionStandard', {rules: [{required: true, message: '请输入环保标准（车型首页）！'}]}]" />
        </a-form-item>
        <a-form-item
          label="综合油耗(工信部)（车型首页）"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入综合油耗(工信部)（车型首页）" v-decorator="['oilConsumption', {rules: [{required: true, message: '请输入综合油耗(工信部)（车型首页）！'}]}]" />
        </a-form-item>
        <a-form-item
          label="最大功率（车型首页）"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入最大功率（车型首页）" v-decorator="['maxPower', {rules: [{required: true, message: '请输入最大功率（车型首页）！'}]}]" />
        </a-form-item>
        <a-form-item
          label="最大扭矩（车型首页）"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入最大扭矩（车型首页）" v-decorator="['maxTorsion', {rules: [{required: true, message: '请输入最大扭矩（车型首页）！'}]}]" />
        </a-form-item>
        <a-form-item
          label="能源类型（车型首页）"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入能源类型（车型首页）" v-decorator="['energyType', {rules: [{required: true, message: '请输入能源类型（车型首页）！'}]}]" />
        </a-form-item>
        <a-form-item
          label="快充时间（车型首页）"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入快充时间（车型首页）" v-decorator="['fastChargingTime', {rules: [{required: true, message: '请输入快充时间（车型首页）！'}]}]" />
        </a-form-item>
        <a-form-item
          label="慢充时间（车型首页）"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入慢充时间（车型首页）" v-decorator="['slowChargingTime', {rules: [{required: true, message: '请输入慢充时间（车型首页）！'}]}]" />
        </a-form-item>
        <a-form-item
          label="续航里程（车型首页）"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入续航里程（车型首页）" v-decorator="['enduranceMileage', {rules: [{required: true, message: '请输入续航里程（车型首页）！'}]}]" />
        </a-form-item>
        <a-form-item
          label="0,未删除
            1,已删除"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入0,未删除
            1,已删除" v-decorator="['deleteFlag', {rules: [{required: true, message: '请输入0,未删除
            1,已删除！'}]}]" />
        </a-form-item>
        <a-form-item
          label=""
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入" v-decorator="['createBy', {rules: [{required: true, message: '请输入！'}]}]" />
        </a-form-item>
        <a-form-item
          label=""
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入" v-decorator="['updateBy', {rules: [{required: true, message: '请输入！'}]}]" />
        </a-form-item>
        <a-form-item
          label=""
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入" v-decorator="['remark', {rules: [{required: true, message: '请输入！'}]}]" />
        </a-form-item>
        <a-form-item
          label=""
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入" v-decorator="['bmpId', {rules: [{required: true, message: '请输入！'}]}]" />
        </a-form-item>
        <a-form-item
          label="数据状态（1：相似度较高，不用合并；2：匹配度较低，定义为新增；3：需要手动合并; 4:数据无效;6.在中台查出多条数据）"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入数据状态（1：相似度较高，不用合并；2：匹配度较低，定义为新增；3：需要手动合并; 4:数据无效;6.在中台查出多条数据）" v-decorator="['dataStatus', {rules: [{required: true, message: '请输入数据状态（1：相似度较高，不用合并；2：匹配度较低，定义为新增；3：需要手动合并; 4:数据无效;6.在中台查出多条数据）！'}]}]" />
        </a-form-item>
        <a-form-item
          label="数据存储规则（1:车系不存在，新增数据至中台；2：年款相同，指导价相同，定义为同一车型，与中台车型建立关系"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入数据存储规则（1:车系不存在，新增数据至中台；2：年款相同，指导价相同，定义为同一车型，与中台车型建立关系" v-decorator="['dataRule', {rules: [{required: true, message: '请输入数据存储规则（1:车系不存在，新增数据至中台；2：年款相同，指导价相同，定义为同一车型，与中台车型建立关系！'}]}]" />
        </a-form-item>
        <a-form-item
          label="最高相似度"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入最高相似度" v-decorator="['mostSimilar', {rules: [{required: true, message: '请输入最高相似度！'}]}]" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { autohomeVehicleModelEdit } from '@/api/modular/main/autohomevehiclemodel/autohomeVehicleModelManage'
  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      // 初始化方法
      edit (record) {
        this.visible = true
        setTimeout(() => {
          this.form.setFieldsValue(
            {
              id: record.id,
              systemId: record.systemId,
              qczjModelId: record.qczjModelId,
              brandId: record.brandId,
              brandName: record.brandName,
              seriesId: record.seriesId,
              seriesName: record.seriesName,
              modelName: record.modelName,
              dscModelId: record.dscModelId,
              modelJson: record.modelJson,
              modelCode: record.modelCode,
              appearanceColor: record.appearanceColor,
              interiorColor: record.interiorColor,
              saleType: record.saleType,
              modelYear: record.modelYear,
              exhaust: record.exhaust,
              shiftBox: record.shiftBox,
              launchDate: record.launchDate,
              bodyTypeName: record.bodyTypeName,
              engineTypeName: record.engineTypeName,
              carGrade: record.carGrade,
              carType: record.carType,
              subBrandNo: record.subBrandNo,
              subBrandName: record.subBrandName,
              guidingPrice: record.guidingPrice,
              emissionStandard: record.emissionStandard,
              oilConsumption: record.oilConsumption,
              maxPower: record.maxPower,
              maxTorsion: record.maxTorsion,
              energyType: record.energyType,
              fastChargingTime: record.fastChargingTime,
              slowChargingTime: record.slowChargingTime,
              enduranceMileage: record.enduranceMileage,
              deleteFlag: record.deleteFlag,
              createBy: record.createBy,
              updateBy: record.updateBy,
              remark: record.remark,
              bmpId: record.bmpId,
              dataStatus: record.dataStatus,
              dataRule: record.dataRule,
              mostSimilar: record.mostSimilar
            }
          )
        }, 100)
      },
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object' && values[key] != null) {
                values[key] = JSON.stringify(values[key])
              }
            }
            autohomeVehicleModelEdit(values).then((res) => {
              if (res.success) {
                this.$message.success('编辑成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('编辑失败')//  + res.message
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
